# -*- coding: utf-8 -*-
from datetime import timedelta
from jms.ods.lmdm.yl_lmdm_sys_customer import jms_ods__yl_lmdm_sys_customer
from utils.operators.spark_sql_operator import SparkSqlOperator

yl_ods__yl_lmdm_sys_customer = SparkSqlOperator(
    task_id='yl_ods__yl_lmdm_sys_customer',
    email='chenhongping@yl-scm.com',
    pool_slots=1,
    master='yarn',
    execution_timeout=timedelta(minutes=60),
    name='yl_ods__yl_lmdm_sys_customer_{{ execution_date | cst_ds_nodash }}',
    sql='jms/ods2/lmdm/yl_lmdm_sys_customer/bushu.hql',
    executor_cores=2,
    executor_memory='3G',
    num_executors=2,  # spark.dynamicAllocation.enabled 为 True 时，num_executors 表示最少 Executor 数
    conf={'spark.dynamicAllocation.enabled'                    : 'true',  # 动态资源开启
          'spark.shuffle.service.enabled'                      : 'true',  # 动态资源 Shuffle 服务开启
          'spark.dynamicAllocation.maxExecutors'               : 5,  # 动态资源最大扩容 Executor 数
          'spark.dynamicAllocation.cachedExecutorIdleTimeout'  : 60,  # 动态资源自动释放闲置 Executor 的超时时间(s)
          'spark.sql.sources.partitionOverwriteMode'           : 'dynamic',  # 允许删改已存在的分区
          'spark.executor.memoryOverhead'                      : '1G',  # 堆外内存
          },
    hiveconf={'hive.exec.dynamic.partition'               : 'true',  # 动态分区
              'hive.exec.dynamic.partition.mode'          : 'nonstrict',
              'hive.exec.max.dynamic.partitions'          : 5,  # 每天生成 20 个分区
              'hive.exec.max.dynamic.partitions.pernode'  : 5,  # 每天生成 20 个分区
              },
)

yl_ods__yl_lmdm_sys_customer << jms_ods__yl_lmdm_sys_customer
